<template>
  <div class="address-ist">
   <van-address-list
  :list="list"
  :disabled-list="disabledList"
  disabled-text="以下地址超出配送范围"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
/>
  </div>
</template>

<script>
import Vue from 'vue'
import { AddressList, Toast } from 'vant'
import { getAddRess } from '@/API/getAddRess'

Vue.use(AddressList)
Vue.use(Toast)
export default {
  name: 'addressList',
  data () {
    return {
      // chosenAddressId: 64,
      // switchable: false,
      list: [
        // {
        //   id: '1',
        //   name: '张三',
        //   tel: '13000000000',
        //   address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        //   isDefault: true
        // }
      ],
      disabledList: [
        {
          id: '3',
          name: '王五',
          tel: '1320000000',
          address: '浙江省杭州市滨江区江南大道 15 号'
        }
      ]
    }
  },
  methods: {
    onAdd () {
      this.$router.push('/address/edit')
      // Toast('新增地址')
    },
    onEdit (item, index) {
      console.log(item, index)
      this.$router.push({ path: '/address/ament', query: item })
      // Toast('编辑地址:' + index)
    }
  },
  created () {
    console.log(this.list)
    if (getAddRess()) {
      getAddRess().then(res => {
        console.log(res)
        this.list = res.body.resAddress.map(item => ({
          id: item.id,
          name: item.name,
          tel: item.phone,
          address: `${item.area}  ${item.detail}`,
          isDefault: item.is_default,
          ZIP_code: item.ZIP_code
        }
        ))
      })
    }
  },
  // mounted () {
  // },
  updated () {
    Array.from(document.querySelector('.address-ist').querySelectorAll('.van-icon-success')).forEach(item => {
      if (item) item.style.display = 'none'
    })
  }
}
</script>

<style lang="scss" scoped>
// .address-ist {
//   .van-radio__icon{
//     border: none !important;
//     background: red;
//   }
// }
</style>
